home *** CD-ROM | disk | FTP | other *** search
- /*
- FILE: analyze.c
- PROJECT: Ford grant DSP
- AUTHOR: Ben Denckla
- COMMENT: Collects statistics about the signal.
- */
-
- #include "aiff.h"
-
- #include <stdio.h>
- #include <math.h>
- #include <limits.h>
- #include <string.h>
-
- #define BARMAX 60
- #define BINSLOG2 4
- #define BINS (1 << BINSLOG2)
- #define HSHIFT (16 - BINSLOG2)
- #define HMASK ( (BINS - 1) << HSHIFT )
-
- #define BINPRINT( ofs ) \
- for (i=ofs + BINS/2 - 1; i>=ofs; i--) { \
- barlen = (float) BARMAX * histogram[i]/histmax; \
- printf( "bin %4d: %8lx %.*s\n", \
- i - ofs*2, histogram[i], barlen, bar ); \
- }
-
- int take_input = 1, make_output = 0;
-
- static short min, max;
- static long histogram[BINS] = {0};
- static double sum_of_squares = 0.0;
-
- void init_process( void ) {
- if ( (ba.com.wdsi < 9) || (ba.com.wdsi > 16) )
- err( "Cannot process a file with this word size" );
- }
-
- void term_process ( void ) {
- double rms;
- int i, barlen;
- long histmax = 0;
- char bar[80];
-
- memset( bar, '*', BARMAX );
- rms = sqrt( sum_of_squares / (ba.com.chan * ba.com.fram) );
- for (i=0; i<BINS; i++)
- if ( histogram[i] > histmax ) histmax = histogram[i];
-
- printf( "rms val: %.1lf\nmin: %6hd\nmax: %6hd\n", rms, min, max );
-
- BINPRINT( 0 );
- BINPRINT( BINS/2 );
- }
-
- void process_samdat ( long buflen ) {
- register short *td, *endd;
-
- td = d;
- min = max = *td;
- endd = &td[ba.com.chan * buflen];
-
- do {
- if ( *td < min ) min = *td;
- if ( *td > max ) max = *td;
- sum_of_squares += (float) *td * *td;
- histogram[ ((unsigned short ) *td & HMASK) >> HSHIFT ]++;
- td++;
- } while ( td < endd );
- }